package hh.engine;

import hh.Column;
import hh.visit.Acceptor;
import hh.visit.TemplateVisitor;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Setter
@Accessors(chain = true)
@Getter
public class Table extends Acceptor {
    public String tableName;
    public String tableComment;
    public List<Column> columns;

    public Table() {
    }

    public Table(String tableName, String tableComment) {
        this.tableName = tableName;
        this.tableComment = tableComment;
    }

    @Override
    public void accept(TemplateVisitor visitor) {
        visitor.visit(this);
    }


    public void addColumn(Column column) {
        if (columns == null) columns = new ArrayList<>(16);
        columns.add(column);
    }
    
    public List<String> getImportsStr() {
        return columns.stream().filter(e -> !e.columnJavaType.getName().startsWith("java.lang."))
                .map(e -> e.columnJavaType.getName()).collect(Collectors.toList());
    }
}
